package com.haoshuang.zhouzhoubang.ui.activity

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.haoshuang.zhouzhoubang.databinding.ActivityOrderWcBinding
import com.haoshuang.zhouzhoubang.model.bean.CompleteOrderListBean
import com.haoshuang.zhouzhoubang.ui.adapter.PushAdapter2
import com.haoshuang.zhouzhoubang.ui.vm.OrderWcViewModel
import com.mufeng.libs.base.BaseVMActivity
import com.mufeng.libs.core.finishAll
import com.mufeng.libs.core.setEmptyData
import com.mufeng.libs.core.setupData
import com.mufeng.libs.state.observeState
import com.mufeng.libs.utils.view.clickWithTrigger


/**
 *  服务订单  完成订单
 */
class OrderWcActivity : BaseVMActivity<OrderWcViewModel, ActivityOrderWcBinding>() {

    override fun initView(savedInstanceState: Bundle?) {
        binding.appBar.ivBack.clickWithTrigger { finish() }
        binding.appBar.tvTitle.text = "服务订单"
    }

    var data = arrayListOf<CompleteOrderListBean.Data>()
    lateinit var adapter: PushAdapter2
    override fun initData() {
        adapter= PushAdapter2(data)
        binding.recyclerView.layoutManager = LinearLayoutManager(this)
        binding.recyclerView.adapter=adapter
        adapter.setEmptyData()
        binding.refreshLayout.setOnRefreshListener {
            isShowing = false
            p = 1
            getNet()
        }
        binding.refreshLayout.setOnLoadMoreListener {
            isShowing = false
            p++
            getNet()
        }

        p = 1
        getNet()

    }

    private fun getNet() {

        vm.getCompleteOrderList("page" to p, "limit" to 10)

    }

    override fun startObserve() {
        vm.getCompleteOrderListData.observeState(this){
            onLoading {
                showLoading()
            }
            onError {code, msg ->
                dismissLoading()
                binding.refreshLayout.finishAll()
            }
            onSuccess {
                dismissLoading()
                val list = it?.data
                binding.refreshLayout.setupData(list, data, adapter, p)
            }
        }
    }

}